package com.axi.resplan;


import java.util.*;
/*
Date now = new Date(); // initialise to current UTC Date/Time
SimpleDateFormat sdf = new SimpleDateFormat( "EEEE yyyy/MM/dd hh:mm:ss aa zz : zzzzzz" );
sdf.setTimeZone( TimeZone.getDefault() ); // local time
String dateString = sdf.format( now );
*/



public class Task 
{
	final static int DAILY_WORKING_HOURS = 8;
	//Master data
	//name of the task
	protected String _name = "";
	
	//ID to reflect the task in the DB
	String _taskId = "";
	
	//length of the task in hours
	int _lengthInHour = 0;
	
	//_deadline - latest is the default which is the last date of the project
	Date _latestEndDate;

	// - The default is the project start. It can be changed for various reasons 
	Date _earliestStartDate;
	
	//_startDate - the date when the task starts according to the calculated plan
	Date _startDate;

	//_endDate - the date when the task ends according to the calculated plan
	Date _endDate;
	
	//reference to the parent timeTable that handles this task
	TimeTable _parentTimeTabel;
	
	//precondition list
	Hashtable<String, Task> _precondition;

	//possible resources list
	Hashtable<String, String> _resource = new Hashtable();
	
	//working variables
	String _assignedResource;
	
	/** start time for working on planning
	 * This is relative to the earliest start time in the project.
	 */
	int _startTime = 0;
	
	/**
	 * Effective working time can be longer if holidays is booked on days that would be reserved for the given job.
	 */
	int _effectiveWorkTiem = 0;
	
	/** Specifies the order of processing. Index tells where this task placed in the queue of a resource */
	int _index = -1;
	
	String _owner;
	
	/**
	 * Constructor
	 * 
	 * @param argName - task name, or visual ID
	 * @param argId - DB id in task table
	 * @param argDefaultStart - the earliest start
	 * @param argDefaultEnd - the latest end
	 * @param argLength - length of the task in hours
	 * @param argTimeTable - The parent TimeTable that handles this task
	 */
	public Task (String argName, 
			String argId, 
			Date argDefaultStart, 
			Date argDefaultEnd, 
			Integer argLength,
			TimeTable argTimeTable)
	{
		
		this._name = argName;
		this._taskId = argId;
		this._earliestStartDate = argDefaultStart;
		this._latestEndDate = argDefaultEnd;
		this._lengthInHour = argLength;
		this._parentTimeTabel = argTimeTable;
		
		this._precondition = new Hashtable<String, Task>();
		
		reset();
		
	}
	
	/**
	 * Reset the Task. Eliminates all planning results
	 */
	public void reset()
	{
		_assignedResource = "";
		_startDate = this._earliestStartDate; 
		_index = -1;		
	}
	

	/**
	 * Set a task as precondition
	 * @param argPre
	 */
	public void addPrecondition( Task argPre )
	{
		_precondition.put(argPre._taskId, argPre);
	}
	
	/**
	 * Remove a given precondition task
	 * @param argPre
	 */
	public void removePrecondition( Task argPre )
	{
		_precondition.remove(argPre._taskId);		
	}

	/**
	 * Remove all precondition.
	 */
	public void removeAllPrecondition()
	{
		_precondition.clear();		
	}
	
	/**
	 * 
	 * @param argName
	 */
	public void addResource(String argName)
	{
		this._resource.put(argName,  argName);
	}
	
	public void removeResource( String argName )
	{
		this._resource.remove(argName);
	}
	
	
	public void removeAllResources()
	{
		this._resource.clear();
	}

	public Hashtable getResources()
	{
		return _resource;
	}

	public String getName()
	{
		return _name;
	}

	public Date getEarliestStart()
	{
		return this._earliestStartDate;
	}

	public Date getLatestEnd()
	{
		return this._latestEndDate;
	}
	
	public String getTaskId()
	{
		return this._taskId;
	}
	
	public int getLengthInHur()
	{
		return this._lengthInHour;
	}
	
	
	public void setIndex( int argIndex)
	{
		_index = argIndex;
	}
	
	public int getIndex()
	{
		return _index;
	}
	
	public void setOwner(String argOwner)
	{
		_owner = argOwner;
	}
	
	public String getOwner()
	{
		return _owner;
	}
	
	public String toString()
	{
		return "<"+_owner+","+_index+">";
	}
	

}
